package com.wjk.kylin.mall.order.controller;

import com.alibaba.fastjson.JSON;
import com.wjk.kylin.mall.common.core.dto.base.BaseOutDTO;
import com.wjk.kylin.mall.order.bo.OrderBO;
import com.wjk.kylin.mall.order.feign.ProductFeignService;
import com.wjk.kylin.mall.order.mq.MessageDTO;
import com.wjk.kylin.mall.order.mq.RabbitProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RefreshScope
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private RabbitProducer rabbitProducer;

    //data id = mall-order-dev.yaml
    /* 配置内容
    * upload:
        type: fastdfs
    * */

    @Value("${upload.type:oss}") //:oss是为了防止未配置，默认值为oss
    private String uploadType;

    @Autowired
    private ProductFeignService productFeignService;

    @GetMapping("/{remark}/{delayTime}")
    public String test(@PathVariable("remark") String remark,@PathVariable("delayTime") Integer delayTime) {
        OrderBO bo = new OrderBO();
        bo.setId(1001L);
        bo.setMemberId(1002L);
        bo.setOrderNumber("20220128230100001");
        MessageDTO msg = new MessageDTO();
        msg.setData(JSON.toJSONString(bo));
        msg.setMsgId(1L);
        msg.setDelayTime(delayTime * 1000);
        msg.setMsgTime(new Date());
        msg.setMsgType(1);
        msg.setRemark(remark);

        rabbitProducer.sendTtlMsg(msg, msg.getDelayTime());
        return "order.test";
    }

    @GetMapping("/feign")
    public BaseOutDTO feign() {
        return productFeignService.demo();
    }

    @GetMapping("/config")
    public String config() {
        return uploadType;
    }


}
